package com.youngking.guns.modular.auth.validator.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.youngking.guns.core.shiro.ShiroKit;
import com.youngking.guns.modular.auth.validator.IReqValidator;
import com.youngking.guns.modular.auth.validator.dto.Credence;
import com.youngking.guns.modular.system.model.User;
import com.youngking.guns.modular.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 账号密码验证
 *
 * @author fengshuonan
 * @date 2017-08-23 12:34
 */
@Service
public class DbValidator implements IReqValidator {

    @Autowired
    private IUserService userService;

    @Override
    public LoginP validate(Credence credence) {
        User user = userService.getByAccount(credence.getCredenceName());
        EntityWrapper aw = new EntityWrapper();
        aw.setEntity(new User());
        aw.where("mobile = {0}", credence.getCredenceName());
        User memberP = userService.selectOne(aw);
        LoginP loginP = new LoginP();
        if (user != null) {
           //String encrypt = theMember.getEncrypt();
            String OldPWD = user.getPassword();
            //验证用户名密码
           String PWD = ShiroKit.md5(user.getPassword(), user.getSalt());
           //if(OldPWD.equals(PWD)){
           //     loginP.setMember(theMember);
            //   loginP.setIspass(true);
         //  }
        }else if(memberP!=null){
          //  String encrypt = memberP.getEncrypt();
            String OldPWD = memberP.getPassword();
            //验证用户名密码
            String PWD = ShiroKit.shuoduoduomd5(credence.getCredenceCode(),"666");
            if(OldPWD.equals(PWD)){
              //  loginP.setMember(memberP);
                loginP.setIspass(true);
            }
        }
        return loginP;
    }
}
